package com.vtuzx.kingdee.xqc_core.dao;

import com.vtuzx.core.db.mongo.impl.VtuzxDaoImpl;
import org.bson.Document;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@Component
public class AllocationDetailDao extends VtuzxDaoImpl {
    /** 集合名称 */
    public static final String NAME = "t_allocation_detail";

    public AllocationDetailDao() {
        super(NAME);
    }


    public Iterator<Document> stockCount(Criteria cond) {
        List<Document> docList = new ArrayList<>();
        docList.add(new Document("$unwind", new Document("path", "$inventory")));
        docList.add(new Document("$match", cond.getCriteriaObject()));
        docList.add(new Document("$group",
                new Document("_id", new Document("stockNo", "$stockNo").append("materialNo", "$inventory.materialNo"))
                        .append("totalBoxCount", new Document("$sum", 1)).append("totalCount", new Document("$sum", "$count"))));
        return this.aggregate(docList);
    }
}
